import {createRouter, createWebHistory} from 'vue-router';
import Home from "@/views/Home.vue";

const router = createRouter({
    history: createWebHistory(import.meta.env.BASE_URL),
    routes: [
        {
            path: '/',
            redirect: '/home',
        },
        {
            path: '/home',
            name: 'home',
            meta: {title: '首页'},
            component: () => import('@/views/Home.vue')
        },
        {
            path: '/login',
            name: 'login',
            meta: {title: '登录页面'},
            component: () => import('@/views/Login.vue')
        },
        {
            path: '/itemDetail/:id',
            name: 'itemDetail',
            meta: {title: '商品详情'},
            component: () => import('@/views/ItemDetail.vue')
        },
        {
            path: '/business',
            name: 'business',
            component: () => import('@/views/BusinessManager.vue'),
            children: [
                {
                    path: 'item',
                    name: 'item',
                    meta: {title: "商品管理"},
                    component: () => import('@/views/BusinessItem.vue'),
                },
                {
                    path: 'shop',
                    name: 'shop',
                    meta: {title: "店铺信息管理"},
                    component: () => import('@/views/BusinessPerson.vue'),
                },
                {
                    path: 'orders',
                    name: 'orders',
                    meta: {title: "订单管理"},
                    component: () => import('@/views/BusinessOrder.vue')
                }
            ]
        },
        {
            path: '/user',
            name: 'user',
            component: () => import('@/views/UserManager.vue'),
            children: [
                {
                    path: 'person',
                    name: 'person',
                    meta: [{title: "个人信息"}],
                    component: () => import('@/views/UserPerson.vue')
                },
                {
                    path: 'order',
                    name: 'order',
                    meta: [{title: "我的订单"}],
                    component: () => import('@/views/UserOrder.vue')
                }
            ]
        },
        {
            path: '/register',
            name: 'register',
            component: () => import('@/views/Register.vue')
        },
    ]
});

router.beforeEach((to, from, next) => {
    document.title = to.meta.title || '默认标题';
    next();
});

export default router;